package cn.yitun.chat.yitunserverimcore.general.main.push.group;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.group.GroupRelationPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 群内关系相关
 * Date 2019-01-27 21:43:21<br>
 * Description
 * 
 * @author yitun<br>
 * @since 1.1
 */
@Service
public class GroupRelationPush {
	//1.2.203
	final String action = ActionTypeConstant.GROUP_RELATION_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 添加
	 * @param key
	 * @param groupId
	 * @param userId
	 */
	public void pushAdd(Long key, Long groupId, Long userId) {
		String method = GroupRelationPushMethodEnum.ADD.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupId", groupId);
		writeHandler.push(userId, message);
	}

	/**
	 * 更新备注
	 * @param key
	 * @param groupId
	 * @param remark
	 * @param userId
	 */
	public void pushUpdateRemark(Long key, Long groupId, String remark, Long userId) {
		String method = GroupRelationPushMethodEnum.UPDATE_REMARK.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupId", groupId);
		message.bodyPut("remark", remark);
		writeHandler.push(userId, message);
	}

	/**
	 * 转移到分组
	 * @param key
	 * @param groupIds
	 * @param categoryId
	 * @param userId
	 */
	public void pushMoveCategory(Long key, List<Long> groupIds, Long categoryId, Long userId) {
		String method = GroupRelationPushMethodEnum.MOVE_CATEGORY.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupIds", groupIds);
		message.bodyPut("categoryId", categoryId);
		writeHandler.push(userId, message);
	}

	/**
	 * 删除
	 * @param key
	 * @param groupId
	 * @param userId
	 */
	public void pushDelete(Long key, Long groupId, Long userId) {
		List<Long> userIds = new ArrayList<>();
		userIds.add(userId);
		pushDelete(key, groupId, userIds);
	}

	/**
	 * 删除
	 * @param key
	 * @param groupId
	 * @param userIds
	 */
	public void pushDelete(Long key, Long groupId, List<Long> userIds) {
		String method = GroupRelationPushMethodEnum.REMOVE.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("groupId", groupId);
		writeHandler.push(YitunStringUtil.toStrList(userIds), message);
	}
}
